//清楚Ajax缓存
$(function() {
	$.ajaxSetup({ cashe : false }); 
});
//清楚Ajax缓存

//请求用户的头像
$(function() {
	$.get ("json/userExt_findById", 
		function (data) {
			if(data.headPic == "" || data.headPic == null) {
				return;
			}
			$("#headPic").attr("src", data.headPic);
	});	
});
//请求用户的头像

//请求是否有新的短消息
$(function() {
	$.get("json/MsgFindNew",
		function(data) {
			if(data.yes_1 == 1) {
			  	$(".top-right-pos").css("display", "block");
			}
	});
});
//请求是否有新的短消息

//个人空间iframe框架高度随页面自调
function dyniframesize(iframename) {
	var getFFVersion = navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1];
	//extra height in px to add to iframe in FireFox 1.0+ browsers
	var FFextraHeight = getFFVersion >= 0.1 ? 16 : 0;
		
	var pTar = null;
	if(document.getElementById) {
		pTar = document.getElementById(iframename);
	} else {
		eval('pTar = ' + iframename + ';');
	}
		
	if(pTar && !window.opera) {
		//begin resizing iframe
		pTar.style.display = "block";

		if(pTar.contentDocument && pTar.contentDocument.body.offsetHeight) {
			//ns6 syntax
			pTar.height = pTar.contentDocument.body.offsetHeight + FFextraHeight;
		} else if (pTar.Document && pTar.Document.body.scrollHeight) {
			//ie5+ syntax
			pTar.height = pTar.Document.body.scrollHeight;
		}
	}
		
	if(pTar.height < 860) {
		pTar.height = 860;
	}
}
//个人空间iframe框架高度随页面自调

//个人空间  文章的下拉框菜单
function msg_2_2() {
	$(".con-pos-aticle").css("display","block");
	$("#artical").css("color", "#FF0000");
}

function msg_2_3() {
	$(".con-pos-aticle").css("display","none");
	$("#artical").css("color", "#009FED");
}
//个人空间  文章的下拉框菜单

/*------------个人空间-期刊分类、期刊名称、期刊板块三级联动--------------*/
//期刊分类
$(function() {
	$.get("json/category_find_all", function(data) {
		var str = "";
		for ( var j = 0; j < data.categorys.length; j++) {
			str += "<option value='"+ data.categorys[j].categoryId + "'>" + data.categorys[j].name + "</option>";
		}
		$("#category").append(str);
	});
});
//期刊分类

//某一期刊分类的期刊
function find_bycategoryId() {
	var xx = $("#category option:selected").attr("value");//获取的是select的value值
	$("#board > option:gt(0)").remove();
	$("#periodical > option:gt(0)").remove();
//$.get("json/periodical_findByCateId?now=" + new Date().getTime()+"&id=" + xx, function(data) {
	$.get("json/periodical_findByCateId?id=" + xx, function(data) {
		var str = "";
		for ( var j = 0; j < data.periodicals.length; j++) {
			str += "<option value='"+ data.periodicals[j].periodicalId + "'>" + data.periodicals[j].name + "</option>";
		}
		$("#periodical").append(str);
	});
	$(".category").slideUp("slow");
	$(".perWarning").slideUp("slow");
	$(".warning").slideUp("slow");
	$("#perMsg").slideUp("slow");
}
//某一期刊分类的期刊

//某一期刊的版块
function find_new_1th() {
	$("#board > option:gt(0)").remove();
	if("0" == $("#category  option:selected").attr("value")) {
		$(".warning").css("display", "block");
		$(".category").css("display", "block");
		$(".perWarning").css("display", "none");
	} else {
		$("#periodical").change(function() {
			var xx = $("#periodical option:selected").attr("value");//获取的是select的value值
			$.get("json/perPeriodical_find_1th_byperi?value="+xx, function(data) {
				var id = data.perPeriodicalId;
				$("#periodicalId").val(id);
				var str_1 = "";
				for ( var j = 0; j < data.boards.length; j++) {
					str_1 += "<option value='"+ data.boards[j].boardId + "'>" + data.boards[j].name + "</option>";
				}
				$("#board > option:gt(0)").remove();
				$("#board").append(str_1);
			});
		});
	}
}
//某一期刊的版块

//
$(function() {
	$("#periodical").change(function() {
		if($("#periodical").val() != "0") {
			$(".warning").slideUp("slow");
			$(".perWarning").slideUp("slow");
		}
	});
});
/*------------个人空间-期刊分类、期刊名称、期刊板块三级联动--------------*/

/*------------个人空间    评论管理JS--------------*/
function selectPer() {
	$(".periodicalWarning").slideUp("slow");
	$("#perPeriodical > option:gt(0)").remove();
}

function isSelectPer() {
	if("0" == $("#periodical option:selected").attr("value")) {
		$(".periodicalWarning").slideDown("slow");
		return false;
	}
	return true;
}
function selectNum() {
	if($("#perPeriodical").val() == "0") {
		return false;
	} else {
		return true;
	}
}

function commentSub() {
	isSelectPer();
	var flag = selectNum();
	if(flag) {
		$("#commentForm").submit();
	}
}
/*------------个人空间    评论管理JS--------------*/

/*------------个人空间    完善资料   爱好--------------*/
// 爱好
function userhobby() {
	var categoryIds = $("#cateogry_Ids").val();
		
	var ids = categoryIds.split(",");
	$.get("json/category_find_all", function(data) {
		var str = "";
		for(var j=0; j<data.categorys.length; j++) {
			var flag = false;
			for(var i=0; i<ids.length; i++) {
				if(data.categorys[j].categoryId == $.trim(ids[i])) {
					str += "<span class='hobby'><input type='checkbox' name='userExt.hobby' checked value=" + data.categorys[j].categoryId + " />" + data.categorys[j].name + "</span>";	
					flag = true;	
				}
			}
			if(flag == false) {
				str += "<span class='hobby'><input type='checkbox' name='userExt.hobby' value=" + data.categorys[j].categoryId + " />" + data.categorys[j].name + "</span>";
			}
		}
		$("#categoryBB").append(str);
	});
}
//爱好

// 性别
$(function() {
	var sex = $("#sex").val();
	if(sex == 2) {
		$("#sex_nan").remove("checked");
		$("#sex_nv").attr("checked", "true");
	} else {
		$("#sex_nan").attr("checked", "true");
		$("#sex_nv").remove("checked");
	}
});
// 性别

//学历
$(function() {
	var degree = $("#degree").val();
	
	if("博士" == degree) {
		$("#degree1").attr("selected", "true");
	} else if("研究生" == degree) {
		$("#degree2").attr("selected", "true");
	} else if("本科" == degree) {
		$("#degree3").attr("selected", "true");
	} else if("专科" == degree) {
		$("#degree4").attr("selected", "true");
	} else if("其他" == degree){
		$("#degree5").attr("selected", "true");
	} else {
		$("#degree0").attr("selected", "true");
	}
});
// 学历
/*------------个人空间    完善资料  --------------*/

/*---------------申请编委-验证------------------*/
//不选择分类不能选择期刊
function isSelectCategory() {
	if("0" == $("#category option:selected").val()) {
		$("#perMsg").slideDown("slow");
		return false;
	}
	return true;
}
//不选择分类不能选择期刊

//是否选择期刊
function selectPeriodical() {
	if($("#periodical").val() == "0") {
		return false;
	} else {
		return true;
	}
}
//是否选择期刊

//申请编委-个人介绍验证
function introValidate() {
	var introStr = $("#introduce").val();
	if(introStr == "") {
		$("#introMsg").slideDown("slow");
		return false;
	} else {
		$("#introMsg").slideUp("slow");
		return true;
	}
}
//申请编委-个人介绍验证

//申请编委-申请理由验证
function reasonValidate() {
	var reasonStr = $("#commitReason").val();
	if(reasonStr == "") {
		$("#reasonMsg").slideDown("slow");
		return false;
	} else {
		$("#reasonMsg").slideUp("slow");
		return true;
	}
}
//申请编委-申请理由验证

//控制表单提交
function submitCommit() {
	isSelectCategory();
	var flag1 = selectPeriodical();
	var flag2 = introValidate();
	var flag3 = reasonValidate();
	if(flag1 && flag2 && flag3) {
		document.getElementById("applyCommitForm").submit();
	}
}
//控制表单提交
/*---------------申请编委-验证------------------*/

/*---------------申请主编-验证-发布文章-关键字样式------------------*/
function chiefVali(inputIdStr) {
	var inputId = "#" + inputIdStr;
	var msgId = inputId + "Msg";
	var inputIdVal = $(inputId).val();
	var html = "说明：关键字之间请用空格隔开";
	var createEjuornalTagStr = "标签之间用空格隔开";
	var createEjuornalBoardStr = "板块之间用空格隔开";
	
	if(inputIdVal == "" || inputIdVal == html || inputIdVal == "0" || inputIdVal == createEjuornalTagStr || inputIdVal == createEjuornalBoardStr) {
		//发表文章时的关键字
		if(inputIdStr == "keywords") {
			//var commentContent = document.getElementById("keywords");
			var commentContent = $(inputId);
			commentContent.attr("class", "commentContent_1");
			commentContent.attr("value", html);
		} else if(inputIdStr == "tag") {
			var tagText = $(inputId);
			tagText.attr("class", "textStyle_2");
			tagText.text(createEjuornalTagStr);
		} else if(inputIdStr == "board") {
			$(inputId).attr("class", "textStyle_2");
			$(inputId).attr("value", "板块之间用空格隔开");
		}
		
		$(msgId).slideDown("slow");
		return false;
	} else {
		$(msgId).slideUp("slow");
		return true;
	}
}

function chiefSubForm() {
	var flag1 = chiefVali("company");
	var flag2 = chiefVali("address");
	var flag3 = chiefVali("businessId");
	var flag4 = chiefVali("businessImg");
	var flag5 = chiefVali("codeId");
	var flag6 = chiefVali("codeImg");
	if(flag1 && flag2 && flag3 && flag4 && flag5 && flag6) {
		document.getElementById("chiefForm").submit();
	}
}
/*---------------申请主编-验证------------------*/

/*---------------发布文章-控制样式---------------*/
//发布文章时用到
function idSelectPer() {
	if("0" == $("#periodical option:selected").attr("value")) {
		$(".warning").css("display", "block");
		$(".category").css("display", "none");
		$(".perWarning").css("display", "block");
		return false;
	} else {
		return true;
	}
}

function selectBoard() {
	if($("#board").val() == "0") {
		return false;
	} else {
		return true;
	}
}
//发布文章时用到
//评论内容框-得到焦点的样式
function commentContent() {
	var commentContent = document.getElementById("keywords");
	if ("说明：关键字之间请用空格隔开" == commentContent.value) {
		commentContent.className = "commentContent_2";
		commentContent.value = "";
	}
}
// 评论内容框-得到焦点的样式

//控制表单提交
function articalSubForm() {
	idSelectPer();
	var flag1 = selectBoard();
	var flag2 = chiefVali('articalTitle');
	var flag3 = chiefVali('enAbstract');
	var flag4 = chiefVali('cnAbstract');
	var flag5 = chiefVali('keywords');
	//var flag6 = chiefVali('editor');	//有编辑器，验证失效  之前被注释掉
	var flag7 = chiefVali('refDoc');
	var editor = UE.getEditor("editor");
	if(!editor.hasContents()) {
		$("#editorMsg").slideDown("slow");
	} else {
		$("#editorMsg").slideUp("slow");
	}
	if(flag1 && flag2 && flag3 && flag4 && flag5  && flag7 && editor.hasContents()) {
		editor.sync();
		document.getElementById("articalForm").submit();
	}
}
//控制表单提交
/*---------------发布文章-控制样式---------------*/

/*---------------完善信息-验证---------------*/
//真是姓名验证
function penNameVali() {
	$("#penNameMsg > span").remove(); /*添加*/
	var penNameStr = $("#zname").val();
	
	if(penNameStr == "") {
		$("#penNameMsg").append("<span>真实姓名不能为空</span>");
	} else {
		return true;
	}
	return false;
}
//真是姓名验证

//电话验证
function telVali() {
	$("#telMsg > span").remove();   
	//var pattern = /((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)/;
	var pattern = /^1\d{10}$|^[1-9]{1,1}\d{6,7}$|^\d{3,4}-\d{7,8}$/;
	var telStr = $("#tel").val();
	var result = pattern.test(telStr);
	if(telStr == "") {
		$("#telMsg").append("<span>电话不能为空</span>");
	} else if(!result) {
		$("#telMsg").append("<span>请输入正确的手机或电话</span>");
	} else {
		return true;
	}
	
	return false;
}
//电话验证

//控制表单提交
function personDataSubForm() {
	var flag1 = penNameVali();
	var flag2 = telVali();
	
	if(flag1 && flag2) {
		$("#personDataForm").submit();
	}
}
//控制表单提交
/*---------------完善信息-验证---------------*/

/*---------------创建期刊-验证---------------*/
//控制表单提交
function createEjuornalSubForm() {
	var flag1 = chiefVali("category");
	var flag2 = chiefVali("ejuornalName");
	var flag3 = chiefVali("cycle");
	var flag4 = chiefVali("ejuIntro");
	var flag5 = chiefVali("hostUnit");
	var flag6 = chiefVali("cover");
	var flag7 = chiefVali("tag");
	var flag8 = chiefVali("board");
	if(flag1 && flag2 && flag3 && flag4 && flag5 && flag6 && flag7 && flag8) {
		$("#createEjuornalForm").submit();
	}
}
//控制表单提交
/*---------------创建期刊-验证---------------*/

/*--------------文本得失焦点样式改变-----------*/
function textFocusStyle(textIdStr) {
	var textId = "#" + textIdStr;
	var tagText = "标签之间用空格隔开";
	var boardText = "板块之间用空格隔开";
	if(tagText == $(textId).val() || boardText == $(textId).val()) {
		$(textId).val("");
		$(textId).attr("class", "textStyle_2");
	}
}
/*--------------文本得失焦点样式改变-----------*/